package cn.hellochaos.generator.mapper;

import cn.hellochaos.generator.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;


/**
* <p>
* 用户表 Mapper 接口
* </p>
*
* @author fmy
* @since 2021-07-17
*/
@Mapper
@Repository
public interface UserMapper extends BaseMapper<User> {

    /**
     * 查询用户名是否存在，若存在，不允许注册
     * 注解@Param(value) 若value与可变参数相同，注解可省略
     * 注解@Results  列名和字段名相同，注解可省略
     * 使用注解的方式写sql框架不会自动注入ideletetag=0的条件
     * @param username
     * @return
     */
    @Select(value = "select u.username,u.password from user u where u.username=#{username} and u.ideletetag=0")
    //这个注解在整个页面都有效，相当于一个resultMap的注解，代替xml
    @Results
            ({@Result(property = "username",column = "username"),
                    @Result(property = "password",column = "password")})
    //                    @Result(property = "ideletetag",column = "ideletetag")
    User findUserByName(@Param("username") String username);



    /**
     * 登录
     * @param user
     * @return
     */
    @Select("select u.user_id from user u where u.username = #{username} and password = #{password} and u.ideletetag=0")
    Long login(User user);

}
